﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SmallBusinessKit.Models.Entities;

namespace SmallBusinessKit.DataAccess.Configurations
{
    public class PersonConfig : EntityTypeConfiguration<Person>
    {
        public PersonConfig()
        {
            #region Relaionships

            #endregion

            #region Properties

            HasKey(p => p.Id);

            Property(p => p.Id)
                    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(32)
                    .IsRequired();

            Property(p => p.IsVisible)
                    //.HasColumnName("Visible") // we're not going to go for legacy compatibility...
                    .HasColumnType("bit")
                    .IsRequired();

            Property(p => p.FirstName)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsRequired();

            Property(p => p.MiddleName)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsOptional();

            Property(p => p.LastName)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsRequired();
            
            Property(p => p.Title)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(128)
                    .IsOptional();

            Property(p => p.Desc)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(2048)
                    .IsOptional();

            Property(p => p.Email)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(256)
                    .IsOptional();

            Property(p => p.Phone)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsOptional();

            Property(p => p.Fax)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsOptional();

            Property(p => p.Address)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(128)
                    .IsOptional();

            Property(p => p.City)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(128)
                    .IsOptional();

            Property(p => p.State)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsOptional();

            Property(p => p.ZipCode)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsOptional();

            Property(p => p.Country)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(64)
                    .IsOptional();
            
            Property(p => p.ImageUrl)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(256)
                    .IsOptional();

            Property(p => p.ImageAltText)
                    .HasColumnType("nvarchar")
                    .HasMaxLength(256)
                    .IsOptional();

            Ignore(p => p.DisplayName);             // These aren't really req'd bcs EF will ignore the properties anyways
            Ignore(p => p.DisplayPhone);            // so DisplayFax is left out to show that :)

            // Property(p => p.DisplayOrder)        // defined in original but never used 
            //        .HasColumnType("int")
            //        .IsOptional();

            #endregion
        }
    }
}
